package com.dyp.mvc.swagger.ctr;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Api(value = "api to test connectivity with related services", produces = "application/json;charset=UTF-8")
@RestController
@RequestMapping(value = "/self")
public class SelfDefineRestfulCtr {
    @ApiOperation(value = "heartbeat detection", notes = "for heartbeat detection", httpMethod = "GET", response = ModelMap.class, tags = {"self"})
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "Success, type is ModelMap \n, example : "
                    + "{\"code\":\"200\",\"desc\":\"it works\"} ", response = ModelMap.class),
            @ApiResponse(code = 500, message = "Service error", response = Error.class) })
    @GetMapping(value = "ping", produces = "application/json;charset=UTF-8")
    public ModelMap test() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        ModelMap map = new ModelMap();
        map.addAttribute("code", "200");
        map.addAttribute("desc", "it works");

        return map;
    }
}
